import entity.City;
import entity.Temperature;
import global.GlobalObject;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Month;
import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

/**
 * @author ypz
 * @date 2021/9/10 11:24
 */
public class StreamTest {
    private static final long ONE_DAY_MS = 1000*60*60*24;
    private static final Random RANDOM = new Random();
    public static List<City> prepareData(
            int numCities, int numTemps) {
        List<City> cities = new ArrayList<>();
        IntStream.range(0, numCities).forEach(i ->
                cities.add(
                        new City(
                                GlobalObject.getInstance().generateName(),
                                GlobalObject.getInstance().generateTemperatures(numTemps)
                        )
                )
        );
        return cities;
    }

    public static void main(String[] args) {
        List<City> cities = prepareData(5, 100);
        //记录八月份所有城市的平均温度
        /*cities.stream().flatMap(c->c.getTemperatures().stream()).filter(t->{
            LocalDate localDate = LocalDateTime.ofEpochSecond(t.getDate().getTime(), 0, ZoneOffset.UTC).toLocalDate();
            return localDate.getMonth() == Month.AUGUST;
        }).map(t->t.getReading()).collect(Collectors.averagingDouble(TestFilterMapReducePerformance::toDouble));*/
    }
}
